package com.sgolub.commanndsonline.dao.entity;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.sgolub.commanndsonline.domain.entity.OperationItem;

/**
 * @author sgolub
 *
 */
@Repository
public class OperationItemDAOImpl implements OperationItemDAO {

    @Autowired
    private SessionFactory sessionFactory;
    
	public  OperationItem get(Integer id) {
		OperationItem  item = ( OperationItem)sessionFactory.
								getCurrentSession().get( OperationItem.class, id);
		return item;
	}

	public void add( OperationItem item) {
		sessionFactory.getCurrentSession().save(item);

	}

	public void update( OperationItem item) {
		sessionFactory.getCurrentSession().update(item);

	}

	public void remove(Integer id) {
		sessionFactory.getCurrentSession().delete(get(id));
	}

	@SuppressWarnings("unchecked")
	public List< OperationItem> list() {
		return sessionFactory.getCurrentSession().createQuery("from  OperationItem").list();
	}

	
    @SuppressWarnings("unchecked")
	public List<OperationItem> listByInventarNr(String inventarNr){
    	return sessionFactory.getCurrentSession().
    			createQuery("from  OperationItem where inventarNr = '" + inventarNr + "'").list();
    }

    
    @SuppressWarnings("unchecked")
	public List<OperationItem> listByAdvertisingRegistryId(Integer advertisingRegistryId){
       	return sessionFactory.getCurrentSession().
    			createQuery("from  OperationItem where fkAdvertisingRegistryId = " + advertisingRegistryId).list();
    }
	
	@SuppressWarnings("unchecked")
	public List< OperationItem> filter() {
		return sessionFactory.getCurrentSession().createQuery("from  OperationItem").list();
	}

	
	
}
